# coding = utf-8
import socket
import pickle
from position import *
import time
import copy

def server_send(new_socket, gp, gv):
    while True:
        # p=copy.deepcopy(gp) # 必须copy，否则传递的只是个指针
        # v=copy.deepcopy(gv)
        p=np.array(gp,dtype='float16')
        v=np.array(gv,dtype='float16')
        v1=np.concatenate((v, np.zeros((len(v),1), dtype='float16')), axis=1) # 使v与p同维
        data=np.concatenate((p,v1), axis=0)
        # print(data.shape)
        new_socket.send(data.tobytes())
        time.sleep(0.03)


def main(p,v):

    client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    addr=("192.168.3.39", 7788)
    while True:
        # print(gv)
        gp=copy.deepcopy(p)
        gv=copy.deepcopy(v)
        # print(p[0])
        time.sleep(0.1)
        client.sendto(pickle.dumps(gp), addr)
        client.sendto(pickle.dumps(gv), addr)
        # print(gp[5])
        
    client.close()
if __name__ == '__main__':
    p = poses()
    v=speeds()
    main(p,v)
# import socket

# ip_port = ('192.168.114.129', 7788)
# client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# while 1:
#     msg = input('>>>：').strip()
#     if msg == 'q':
#         break
#     if not msg:		# 其实，udp的套接字，支持客户端发空的，服务端也能收到空
#         continue
#     client.sendto(msg.encode('utf-8'), ip_port)
#     get_msg, server_addr = client.recvfrom(1024)
#     print(get_msg.decode('utf-8'))  